package trees;

import java.util.*;

public class MaxSlidingWindow {
    public int[] maxSlidingWindow(int[] nums, int k) {
        Queue<Integer> list = new LinkedList<>();

        if (nums.length <= k) {
            Arrays.sort(nums);
            return new int[]{nums[nums.length - 1]};
        }

        List<Integer> result = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            if (i < k - 1) {
                list.add(nums[i]);
            } else {
                list.add(nums[i]);
                result.add(Collections.max(list));
                list.poll();
            }
        }

        return result.stream().mapToInt(Integer::intValue).toArray();
    }

    public static void main(String[] args) {
        MaxSlidingWindow window = new MaxSlidingWindow();
        int[] nums = new int[]{1, -1};
        int k = 1;
        Arrays.stream(window.maxSlidingWindow(nums, k)).forEach(System.out::println);
    }
}
